// JimiAgent.cs created with MonoDevelop
// User: jmartin at 08:29 03/10/2007
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;

namespace JimiAgent
{
	
	
	public class Jimi
	{
		
		private MainWindow win;
		private JimiPosition jp;
		private int offset;
		
		string text;
		
		public Jimi(){
			this.win = new MainWindow ();
			this.win.SizeRequested+=this.position;
			this.automaticResize();
			this.state(JimiState.Normal);
			this.jp=JimiPosition.BottomRight;
			this.position(JimiPosition.BottomRight);
			
			Gdk.Color col = new Gdk.Color();
			//Gdk.Color.Parse("#FEFF89", ref col);
			Gdk.Color.Parse("#ECF4FF", ref col);
			
			this.infoBgColor(col);
			this.windowBgColor(col);
			this.text="";
			this.offset=30;
		}
		
		
		public void setOffset(int off){
			this.offset=off;
		}
		

		
		
		private void automaticResize(){
			int wh=0;
			int ww=0;
			int h=0;
			
			this.win.setInfoWidth(160);
			Gdk.Screen.Default.RootWindow.GetSize(out ww,out wh);
		    h=this.win.getInfoHeight();
			
			if(h>(wh/2)){
				this.win.setInfoWidth(-1);
				
			}
			
		}
		
		public void Dispose(){
			this.win.Destroy();
			this.win.Dispose();
			
		}
		
		public void infoFontFamily(string font){
			this.win.infoFontFamily(font);
			this.write(this.text);
		}

		public void infoFontStyle(Pango.Style style){
			this.win.infoFontStyle(style);
			this.write(this.text);			
		}	
	
		public void infoFontSize(int size){
			this.win.infoFontSize(Pango.Units.FromPixels(size));
			this.write(this.text);
		}
       		
		
//		public bool speak(string text){
//
//			System.Diagnostics.Process texttowav;
//			texttowav = new System.Diagnostics.Process();
//			texttowav = System.Diagnostics.Process.Start(cmd, "not"+i+".txt -o not"+i+".wav");
//			
//			texttowav.WaitForExit();
//			texttowav.Close();
//		}
		
		public void state(JimiState i){
			
			switch (i) { 
            case JimiState.Normal:
               win.setPixbuf("normal.png");
               break;
            case JimiState.Nervous:
               win.setPixbuf("nervous.png");
                break;
			case JimiState.Happy:
               win.setPixbuf("happy.png");
                break;
			case JimiState.Sleep:
               win.setPixbuf("sleep.png");
                break;
  
            default:
                win.setPixbuf("normal.png");
               break;
			}
		}
		
		public void position(JimiPosition i){
			int wh=0;
			int ww=0;
			int h=0;
			int w=0;
			Gdk.Screen.Default.RootWindow.GetSize(out ww,out wh);
			this.win.GetSize(out w,out h);
			this.jp=i;
			
			w=w+this.offset;
			h=h+this.offset;
			
			switch (i) { 
            case JimiPosition.TopLeft:
				this.moveTo(0+this.offset,0+this.offset);
               break;
            case JimiPosition.TopRight:
                this.moveTo(ww-w-this.offset,0+this.offset);
                break;
			case JimiPosition.BottomLeft:
               this.moveTo(0+this.offset,wh-w-this.offset);
                break;
			case JimiPosition.BottomRight:
               this.moveTo(ww-w-this.offset,wh-h-this.offset);
                break;
  
			}
		}
		
	
		
		
		public void position(object obj, Gtk.SizeRequestedArgs args){
			
			this.position(this.jp);
		}		
		
		
		public void write(string text ){
			this.win.write(text);
			this.text=text;
			this.automaticResize();
		}
		
		public void show(){
			this.win.Show ();
		}
		
		public void show(int s){
			this.win.Show ();
			//afegeix el timer per als seguents redibuixos
			GLib.Timeout.Add ((uint)(s*1000), new GLib.TimeoutHandler(hide));
			
			
			
		}

		
		public void drawTrans(){
			this.win.drawTrans();
		}
		
		public bool hide(){
			this.win.Hide();
			return false;
		}
		
		public void moveTo(int x,int y){
			
			this.win.Move(x,y);
		}
		
		public void infoBgColor(Gdk.Color color){
			this.win.infoBgColor(color);
			
			
		}
		
		public void windowBgColor(Gdk.Color color){
			this.win.windowBgColor(color);
			
			
		}
		
	}
}
